<script>
import Vue from 'vue'
import { mapState, mapActions, mapMutations } from 'vuex'

export default {
  // 腾讯云IM集成-----------------start--------------------------
  globalData: {
    // userInfo: userID userSig token phone
    userInfo: null,
    // 个人信息
    userProfile: null,
    isTUIKit: true,
    headerHeight: 0,
    statusBarHeight: 0,
    SDKAppID: 1400723489,
  },
  computed: {
    ...mapState('user', ['UserInfo']),
  },
  // 腾讯云IM集成-----------------end--------------------------
  onLaunch() {
    console.log('获取系统型号', uni.getSystemInfoSync().osName)

    const updateManager = uni.getUpdateManager()
    updateManager.onCheckForUpdate(function (res) {
      // 请求完新版本信息的回调
      console.log(res.hasUpdate)
    })
    // 下载新版本
    updateManager.onUpdateReady(function () {
      uni.showModal({
        title: '更新提示',
        content: '新版本已经准备好，是否重启应用？',
        success(res) {
          if (res.confirm) {
            // 重启应用
            updateManager.applyUpdate()
          }
        },
      })
    })
    // 新版本下载失败
    updateManager.onUpdateFailed(function (res) {
      // 新的版本下载失败
      uni.showModal({
        title: '已经有新版本了哟~',
        content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~',
      })
    })
  },
  async onShow() {
    if (uni.getStorageSync('Token')) {
      //await this.GetUserInfo()
      // this.updateReadMesNum();
      //this.IMLogin()
    }
    this.setPadding()
  },
  onHide() {
    uni.setStorageSync('showInquiryPop', '')
  },
  mounted() {
    this.setAppInfo()
  },
  methods: {
    ...mapMutations('user', [
      'SET_ADDRESS',
      'SET_TOKEN',
      'SET_NOREADNUM',
      'SET_SHOWLOCATION',
      'SET_ISIOS',
    ]),
    ...mapMutations(['set_showInquiryPop']),
    ...mapActions('user', ['GetUserInfo', 'IMLogin']),
    setPadding() {
      switch (uni.getSystemInfoSync().platform) {
        case 'android':
          console.log('运行Android上')
          this.SET_ISIOS(false)
          break
        case 'ios':
          console.log('运行iOS上')
          this.SET_ISIOS(true)
          break
        default:
          this.SET_ISIOS(true)
          console.log('运行在开发者工具上')
          break
      }
    },
    // 获取系统栏高度
    async setAppInfo() {
      let that = this
      return new Promise((resolve, reject) => {
        uni.getSystemInfo({
          success: function (e) {
            Vue.prototype.StatusBar = e.statusBarHeight
            // #ifdef H5
            Vue.prototype.CustomBar = e.statusBarHeight + 45
            // #endif

            // #ifdef APP-PLUS
            if (e.platform == 'android') {
              Vue.prototype.CustomBar = e.statusBarHeight + 50
            } else {
              Vue.prototype.CustomBar = e.statusBarHeight + 45
            }
            // #endif

            // #ifdef MP-WEIXIN
            let custom = wx.getMenuButtonBoundingClientRect()
            Vue.prototype.Custom = custom
            Vue.prototype.CustomBar =
              custom.bottom + custom.top - e.statusBarHeight
            // #endif
          },
        })
      })
    },
  },
}
</script>

<style lang="less">
/*每个页面公共css */
@import 'animate.css';
@import './assets/iconfont/iconfont.css';
@import './assets/css/base.less';
@import './assets/css/reset.less';
@import './assets/css/style.less';
</style>
<style>
@import '@/assets/iconfont/iconfont/iconfont.css';
@import '@/assets/iconfont/iconfontColor/iconfontColor.css';
</style>
<style lang="scss">
@import '@/assets/css/theme.scss';
@import '@/assets/css/common.scss';
@import '@/uni_modules/uview-ui/index.scss';

.search {
  box-sizing: border-box;
  width: 100%;
  margin: 0 !important;
  padding: 0 24rpx 0rpx 24rpx !important;
  background-color: #fff !important;

  .dark {
    color: #666666;
  }

  &-b {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 16rpx;

    &::v-deep .u-border {
      border: none;
    }

    &::v-deep .u-input {
      background-color: #f5f7fa !important;
    }

    &::v-deep .uni-input-placeholder {
      font-size: 28rpx;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #666666;
    }
  }

  &-c {
    margin-bottom: 16rpx;
  }

  .cart {
    margin-left: 10rpx;
  }
}

//两行溢出
.multi-ellipsis-1 {
  width: 100%;
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box;
  /** 对象作为伸缩盒子模型显示 **/
  -webkit-box-orient: vertical;
  /** 设置或检索伸缩盒对象的子元素的排列方式 **/
  -webkit-line-clamp: 1;
  /** 显示的行数 **/
  overflow: hidden;
  /** 隐藏超出的内容 **/
}

//两行溢出
.multi-ellipsis-2 {
  width: 100%;
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box;
  /** 对象作为伸缩盒子模型显示 **/
  -webkit-box-orient: vertical;
  /** 设置或检索伸缩盒对象的子元素的排列方式 **/
  -webkit-line-clamp: 2;
  /** 显示的行数 **/
  overflow: hidden;
  /** 隐藏超出的内容 **/
}

.font-color-origin {
  color: #ff6010 !important;
}

.font-color-green {
  color: #FF5900 !important;
}

button::after {
  border: none;
}
</style>
